<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:calli="http://callimachusproject.org/rdf/2009/framework#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<head>
    <title>Invite a New User</title>
    <link rel="help" href="../../callimachus-for-web-developers#Account_Invitations" target="_blank" title="Help" />
    <script type="text/javascript"><![CDATA[
    jQuery(function($) {
        var origin = window.location.protocol + '//' + window.location.host;
        $('#body').val($('#body').val().replace(/@@REGISTRATION_URL@@/g, origin + '/?register') + origin);
        var messageChanged = false;
        $('#body').change(function(){
            messageChanged = true;
        });
        $('#label').on('change keyup blur', function() {
            if (!messageChanged) {
                var salutation = $(this).val() ? 'Hello ' + $(this).val() : 'Hello';
                $('#body').val($('#body').val().replace(/(^|[\r\n])Hello.*/, '$1' + salutation + ','));
            }
        });
        $('#email').change(function(){
            if (this.value.indexOf('<') >= 0) {
                var name = this.value.substring(0, this.value.indexOf('<')).replace(/^\s+/,'').replace(/\s+$/,'');
                if (name) {
                    $('#label').val(name).change();
                }
                $(this).val(this.value.replace(/.*</, '').replace(/>.*/, '')).change();
            }
        });
        $('#rdfForm').bind('calliRedirect', function(event) {
            if (event.cause.type == 'calliSubmit') {
                event.preventDefault();
                $('#fullname').val($('#label').val());
                $('#msgForm').attr("action", event.resource + '?invite').submit();
                return false;
            }
        });
    }); // ]]>
    </script>
</head>
<body>
    <div id="sidebar">
        <aside>
            <p>E-mail address is used to send an invite and possibly reset the password</p>
            <p>Provide the user's full name</p>
            <p>Provide any additional contact information or affiliation information</p>
            <p>You can customize the message sent in the email here</p>
        </aside>
    </div>
    <form role="form" id="rdfForm" method="POST" action="" enctype="application/rdf+xml" typeof="calli:User calli:Party" autocomplete="off"
            onsubmit="return calli.saveResourceAs(event,calli.slugify($('#email').val()))">
        <fieldset>
            <div class="form-group">
                <label for="email">E-mail address</label>
                <div class="controls">
                    <input id="email" name="email" type="email" class="form-control" required="required" autofocus="autofocus" value="{calli:email}" />
                </div>
            </div>
            <div class="form-group">
                <label for="label">Full name</label>
                <div class="controls">
                    <input id="label" name="label" type="text" class="form-control" required="required" value="{rdfs:label}" />
                </div>
            </div>
            <div class="form-group">
                <label for="comment">Additional information</label>
                <div class="controls">
                    <textarea id="comment" class="form-control" name="comment">{rdfs:comment}</textarea>
                </div>
            </div>
        </fieldset>
    </form>
    <hr />
    <form role="form" id="msgForm" method="POST" action="?invite" enctype="application/x-www-form-urlencoded">
        <fieldset>
            <input type="hidden" name="fullname" id="fullname" />
            <div class="form-group">
                <label for="subject">Welcome subject</label>
                <div class="controls">
                    <input id="subject" name="subject" type="text" class="form-control col-md-5" required="required" value="Account Registration" />
                </div>
            </div>
            <div class="form-group">
                <label for="message">Welcome message</label>
                <div class="controls">
                    <textarea id="body" name="body" class="auto-expand col-md-5" required="required">Hello,

A new account has been created for you using a Callimachus service. Use the
link below to pick a password or other authentication options.

@@REGISTRATION_URL@@

If you have any questions, please contact your systems administrator who set
this up for you.

Kind regards,
The Callimachus service running at </textarea>
                </div>
            </div>
            <div class="form-group">
                <button id="invite" class="btn btn-default" onclick="$('#rdfForm').submit();return false">Invite</button>
            </div>
        </fieldset>
    </form>
</body>
</html>
